<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class BaseController extends Controller
{

    protected $userArr;
    protected $requestArr;
    protected $requestFile;
    protected $requestMethod;

    public function __construct(Request $request)
    {
        //获取POST数据
        $this->requestArr = $request->input();
        unset($this->requestArr['s']);
        //获取file
        $this->requestFile = $request->file();
        $this->requestMethod =  $request->getMethod();

        $this->middleware(function ($request, $next) {
            $userToken = unlockToken(session('adminUserToken'));
            if ($userToken) {
                $loginArr = json_decode($userToken, true);
                if (count($loginArr) > 0 && isset($loginArr['user_id'])) {
                    $this->userArr = $loginArr;
                    view()->share($loginArr);
                } else {
                    redirect('/admin/login')->send();
                }
            } else {
                redirect('/admin/login')->send();
            }
            return $next($request);
        });
    }

    /**
     * @Author    Afree
     * @DateTime  2018-04-24
     * @copyright [成功页跳转]
     * @license   [license]
     * @version   [version]
     * @param     [type]      $msg [description]
     * @param     [type]      $url [description]
     * @return    [type]           [description]
     */
//    public function successShow($msg, $tourl, $time = 5)
//    {
//        $data['msg']   = $msg;
//        $data['tourl'] = $tourl;
//        $data['time']  = $time;
//        view()->share($data);
//    }
//
//    // 页面授权检测
//    public function checkAuth($auth_id, $user_auth, $message = '您无权访问此页面!')
//    {
//        $user_auth = json_decode($user_auth, true);
//        if (!in_array($auth_id, $user_auth)) {
//            showMsg(1002, $message);
//        };
//    }

}
